import {ModalForm, ProFormGroup, ProFormText} from '@ant-design/pro-form'
import type {DictItem, Dispatch} from "umi";
import {DictEffectKeys, dictModelName} from "@/pages/Dict/models/dict.model";

interface HospitalSetModalFormProps {
  initialValues: Partial<DictItem>|undefined;
  createModalVisible: any;
  handleModalVisible: any;
  dispatch: Dispatch
}

const HospitalSetModalForm: React.FC<HospitalSetModalFormProps>
  = ({
       initialValues,
       createModalVisible,
       handleModalVisible,
       dispatch
     }) => {
  if (createModalVisible) {
    return <ModalForm
      title="新建系统字典"
      initialValues={initialValues||{}}
      visible={createModalVisible}
      onVisibleChange={handleModalVisible}
      onFinish={async (value) => {

        if(value.id){
          // 修改
          dispatch({
            type:`${dictModelName}/${DictEffectKeys.UpdateNode}`,
            payload:value
          })
        }else {
          dispatch({
            type:`${dictModelName}/${DictEffectKeys.AddNode}`,
            payload:value
          })
        }
      }}
    >
      <ProFormText
        width="md"
        name="id"
        disabled={true}
        label="id"

      />
      <ProFormGroup>
      <ProFormText
        width="md"
        name="parentId"
        disabled={true}
        label="parentId"
      />
      <ProFormText
        width="md"
        name="value"
        rules={[
          {
            required: true,
            message: "value为必填项",
          },
        ]}
        label="value"
      />
      </ProFormGroup>
      <ProFormGroup>
        <ProFormText
          width="md"
          rules={[
            {
              required: true,
              message: "名称为必填项",
            },
          ]}

          name="name"
          label="节点名称"
        />
        <ProFormText
          width="md"
          rules={[
            {
              required: true,
              message: "编号为必填项",
            },
          ]}
          label="编号"
          name="dictCode"/>
      </ProFormGroup>
    </ModalForm>
  }
    return null



}

export default HospitalSetModalForm;
